package io.sage.modules.enterwarehouse.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import io.sage.annotation.Login;
import io.sage.annotation.LoginUser;
import io.sage.common.utils.R;
import io.sage.modules.employer.entity.Employer;
import io.sage.modules.enterwarehouse.entity.BReturnRecords;
import io.sage.modules.enterwarehouse.service.BReturnRecordsService;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 工具归还表
 *
 * @author xujh
 * @email jhang_mail@163.com
 * @date 2019-07-10 13:59:20
 */
@RestController
@RequestMapping("sage/breturnrecords")
public class BReturnRecordsController {
    @Autowired
    private BReturnRecordsService returnRecordsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ApiOperation("查询员工归还工具列表")
    @Login
    public R list(@ApiIgnore @LoginUser Employer employer ,  @RequestBody JSONObject jsonObject){
    	Integer pageSize = jsonObject.getInteger("pageSize");
    	Integer pageNum = jsonObject.getInteger("pageNum");
		
		//员工id
    	Integer employeeId = employer.getId();

		HashMap<String, Object> paramMap = new HashMap<String, Object>();
		
		paramMap.put("employeeId", employeeId);

		PageHelper.startPage(pageNum, pageSize);// 设置分页的起始码以及页面大小
		List<BReturnRecords> selectReturnRecordsList = returnRecordsService.selectReturnRecordsList(paramMap);

		PageInfo<BReturnRecords> pageInfo = new PageInfo<BReturnRecords>(selectReturnRecordsList);// 传入list就可以了

		return R.ok().put("returnRecordsList", pageInfo);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
    	BReturnRecords returnRecords = returnRecordsService.selectByPrimaryKey(id);
		Map<String, Object> paramMap = new HashMap<String, Object>();

		paramMap.put("returnRecords", returnRecords);

		return R.ok().put("map", paramMap);
    }


}
